#include <cstdio>

int main(int argc, char const* argv[])
{
    int n;
    int result = 0, count = 1;
    while (scanf("%d", &n) != EOF && n != 0) {
        if (n == 1) {
            result += 1;
            count = 1;
        } else if (n == 2) {
            result += 2 * count;
            count++;
        }
    }
    printf("%d", result);
    return 0;
}